﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace Core.Models.Migrations
{
    public partial class roleright : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SysActionSysRole");

            migrationBuilder.DropColumn(
                name: "ControllerName",
                table: "SysAction");

            migrationBuilder.DropColumn(
                name: "Icon",
                table: "SysAction");

            migrationBuilder.DropColumn(
                name: "IsLeaf",
                table: "SysAction");

            migrationBuilder.DropColumn(
                name: "IsMenu",
                table: "SysAction");

            migrationBuilder.DropColumn(
                name: "Method",
                table: "SysAction");

            migrationBuilder.DropColumn(
                name: "Url",
                table: "SysAction");

            migrationBuilder.RenameColumn(
                name: "Title",
                table: "SysAction",
                newName: "Name");

            migrationBuilder.RenameColumn(
                name: "ParentId",
                table: "SysAction",
                newName: "Sort");

            migrationBuilder.AddColumn<int>(
                name: "SysDictionaryTypeId",
                table: "SysDictionary",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "ModuleId",
                table: "SysAction",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "SysModule",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
                    ParentId = table.Column<int>(type: "int", nullable: false),
                    Url = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Iconic = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
                    Sort = table.Column<int>(type: "int", nullable: false),
                    IsLeaf = table.Column<bool>(type: "bit", nullable: false),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysModule", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysRoleModule",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    RoleId = table.Column<int>(type: "int", nullable: false),
                    ModuleId = table.Column<int>(type: "int", nullable: false),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysRoleModule", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysRoleRight",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    RoleModuleId = table.Column<int>(type: "int", nullable: false),
                    ActionId = table.Column<int>(type: "int", nullable: false),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysRoleRight", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysDictionary_SysDictionaryTypeId",
                table: "SysDictionary",
                column: "SysDictionaryTypeId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysDictionary_SysDictionaryType_SysDictionaryTypeId",
                table: "SysDictionary",
                column: "SysDictionaryTypeId",
                principalTable: "SysDictionaryType",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysDictionary_SysDictionaryType_SysDictionaryTypeId",
                table: "SysDictionary");

            migrationBuilder.DropTable(
                name: "SysModule");

            migrationBuilder.DropTable(
                name: "SysRoleModule");

            migrationBuilder.DropTable(
                name: "SysRoleRight");

            migrationBuilder.DropIndex(
                name: "IX_SysDictionary_SysDictionaryTypeId",
                table: "SysDictionary");

            migrationBuilder.DropColumn(
                name: "SysDictionaryTypeId",
                table: "SysDictionary");

            migrationBuilder.DropColumn(
                name: "ModuleId",
                table: "SysAction");

            migrationBuilder.RenameColumn(
                name: "Sort",
                table: "SysAction",
                newName: "ParentId");

            migrationBuilder.RenameColumn(
                name: "Name",
                table: "SysAction",
                newName: "Title");

            migrationBuilder.AddColumn<string>(
                name: "ControllerName",
                table: "SysAction",
                type: "nvarchar(20)",
                maxLength: 20,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Icon",
                table: "SysAction",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<bool>(
                name: "IsLeaf",
                table: "SysAction",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "IsMenu",
                table: "SysAction",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<string>(
                name: "Method",
                table: "SysAction",
                type: "nvarchar(20)",
                maxLength: 20,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Url",
                table: "SysAction",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.CreateTable(
                name: "SysActionSysRole",
                columns: table => new
                {
                    ActionsId = table.Column<int>(type: "int", nullable: false),
                    RolesId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysActionSysRole", x => new { x.ActionsId, x.RolesId });
                    table.ForeignKey(
                        name: "FK_SysActionSysRole_SysAction_ActionsId",
                        column: x => x.ActionsId,
                        principalTable: "SysAction",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SysActionSysRole_SysRole_RolesId",
                        column: x => x.RolesId,
                        principalTable: "SysRole",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysActionSysRole_RolesId",
                table: "SysActionSysRole",
                column: "RolesId");
        }
    }
}
